package com.future.mayi.response;

import com.future.baselib.entity.BaseResponse;
import com.future.mayi.app.App;
import com.future.mayi.model.GoodsDetailModel;
import com.future.mayi.model.IndexModel;
import com.future.mayi.model.IndexTimeModel;

import org.json.JSONException;

import java.util.ArrayList;
import java.util.List;

public class IndexResponse extends BaseResponse {
    private IndexModel model;

    //暂加
    @Override
    public void parseInfo(String content) throws JSONException {
        model = App.getGson().fromJson(content, IndexModel.class);

        if (model == null) return;


        List<GoodsDetailModel> goods = new ArrayList<>();
        if (model.getToday() != null && model.getToday().size() > 0 && model.getToday().get(0).getEnd_second() > 0) {
            int timeTag = 1;
            GoodsDetailModel time = new GoodsDetailModel();
            IndexTimeModel timeModel = new IndexTimeModel();
            timeModel.setTitle("好货推荐·10点上新");
            timeModel.setSubTitle("距团购结束");
            timeModel.setRemainSecond(model.getToday().get(0).getEnd_second());
            timeModel.setTimeTag(timeTag);
            timeModel.setThisTime(System.currentTimeMillis());
            time.setTimeModel(timeModel);
            goods.add(time);
            for (GoodsDetailModel item : model.getToday().get(0).getGoods()) {
                if (item == null) continue;
                item.setTimeTag(timeTag);
                goods.add(item);
            }

        }

        if (model.getTomorrow() != null && model.getTomorrow().size() > 0 && model.getTomorrow().get(0).getEnd_second() > 0) {
            int timeTag = 2;
            GoodsDetailModel time = new GoodsDetailModel();
            IndexTimeModel timeModel = new IndexTimeModel();
            timeModel.setSubTitle("距团购结束");
            timeModel.setTitle("明日截团");
            timeModel.setRemainSecond(model.getTomorrow().get(0).getEnd_second());
            timeModel.setTimeTag(timeTag);
            timeModel.setThisTime(System.currentTimeMillis());
            time.setTimeModel(timeModel);
            goods.add(time);
            for (GoodsDetailModel item : model.getTomorrow().get(0).getGoods()) {
                if (item == null) continue;
                item.setTimeTag(timeTag);
                goods.add(item);
            }
        }

        model.setGoods(goods);

    }

    public IndexModel getModel() {
        return model;
    }
}
